from typing import List


class Solution:
    def xorAllNums(self, nums1: List[int], nums2: List[int]) -> int:
        cnt1 = [0 for _ in range(32)]  # 数组1各位为1的个数
        cnt2 = [0 for _ in range(32)]
        for bit in range(32):
            for num in nums1:
                cnt1[bit] += (num >> bit) & 1
            for num in nums2:
                cnt2[bit] += (num >> bit) & 1
        ans = 0
        for bit in range(32):
            ans += (1 << bit) * (cnt1[bit] * (len(nums2) - cnt2[bit]) + cnt2[bit] * (len(nums1) - cnt1[bit]))
        return ans

    def ii(self, nums1: List[int], nums2: List[int]) -> int:
        ans = 0
        for num1 in nums1:
            for num2 in nums2:
                ans += num1 ^ num2
        return ans


if __name__ == '__main__':
    s = Solution()
    r1 = s.xorAllNums(nums1=[1, 2], nums2=[3, 4])
    r2 = s.ii(nums1=[1, 2], nums2=[3, 4])
    print(r1, r2)
